<template>
	<view :style="Theme">
		<uni-nav-bar leftIcon="arrowleft" :fixed="true" title="登录" />
		<view class="logo">
			<image src="/static/logo.jpg"></image>
		</view>
		<view class="loginForm">
			<view class="row-input">
				<i class="iconfont icon-shouji" />
				<input v-model="form.mobile" placeholder="请输入手机号" maxlength="11" placeholder-class="placeholder" />
			</view>
			<view class="row-input">
				<i class="iconfont icon-mima" />
				<input v-model="form.password" placeholder="请输入密码" maxlength="18" password
					placeholder-class="placeholder" />
			</view>
			<view class="loginBtn" @click="handleLogin">立即登录</view>
			<view class="menuLink">
				<text @click="navTo('/intake/register')">注册账号</text>
				<text @click="navTo('/intake/forget')">忘记密码</text>
			</view>
			<view class="tip-link">
				<view style="display: flex;">
					<checkbox-group @change="handleChange">
						<checkbox :value="isChecked" style="transform: scale(0.6);" color="var(--primary-color)" />
					</checkbox-group>
					<text>我已阅读并同意</text>
					<text class="link" @click="handleYin">《隐私保护协议》</text>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" background-color="#fff">
			<view class="popup-content">
				<view class="qiye1">隐私保护协议</view>
				<view class="qiye2">隐私保护协议。。。。</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import alert from '@/common/sju.alert.js'
	export default {
		data() {
			return {
				form: {
					mobile: '',
					password: ''
				},
				isChecked: false
			}
		},
		components: {

		},
		onLoad() {

		},
		onShow() {

		},
		methods: {
			handleChange(e) {
			  this.isChecked = !e.detail.value[0];
			  this.isChecked = !this.isChecked
			},
			handleYin() {
				this.$refs.popup.open()
			},
			navTo(path) {
				this.sjuNav.navigateTo(path)
			},
			handleLogin() {
				console.log('确认登录')
				if (this.form.mobile === '' || this.form.password === '') {
					alert.showInfo('请填写完整')
				} else if (!this.isChecked) {
					alert.showInfo('请先阅读协议并勾选')
				} else {
					this.sjuRequest("/wx/auth/wxLogin", 'POST', this.form).then(res => {
						console.log(res)
						if (res.errno != 0) {
							alert.showInfo(res.errmsg)
						} else {
							// 存用户信息和token
							uni.setStorageSync('token', res.data.token)
							uni.setStorageSync('userInfo', res.data.userInfo)
							uni.showToast({
								title: '登录成功',
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'success',
								//显示持续时间为 2秒
								duration: 2000
							})
							setTimeout(function() {
								uni.reLaunch({
									url: '/pages/tab/index/index'
								})
							}, 2000)
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.logo {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 300rpx;

		image {
			width: 200rpx;
			height: 200rpx;
			border: 1px solid #eee;
			border-radius: 100%;
		}
	}

	.loginForm {
		padding: 20rpx 60rpx;

		.row-input {
			margin: 30rpx 0rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 0 20rpx;
			height: 100rpx;
			border: 1rpx solid var(--primary-color);
			border-radius: 20rpx;

			image {
				padding: 0rpx 10rpx 0rpx 10rpx;
				width: 50rpx;
				height: 50rpx;
				flex-shrink: 0;
			}

			.iconfont {
				color: var(--primary-color);
				padding: 0rpx 10rpx 0rpx 10rpx;
				flex-shrink: 0;
				font-size: 40rpx;
			}

			.placeholder {
				font-size: 30rpx;
				color: var(--primary-color);
			}

			input {
				font-size: 30rpx;
				padding: 0rpx 40rpx;
				color: var(--primary-color);
				border-left: 3rpx solid var(--primary-color);
			}
		}

		.loginBtn {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 35rpx;
			height: 100rpx;
			border-radius: 20rpx;
			color: #FFFFFF;
			background-color: var(--btn-bg-color);
		}

		.menuLink {
			display: flex;
			justify-content: space-between;
			font-size: 28rpx;
			color: var(--btn-bg-color);
			letter-spacing: 3rpx;
			line-height: 80rpx;
		}
	}

	.tip-link {
		display: flex;
		justify-content: space-between;
		align-items: center;
		letter-spacing: 4rpx;
		font-size: 28rpx;

		.link {
			color: var(--primary-color);
		}

	}

	.popup-content {
		width: 600rpx;
		height: 800rpx;
		background: #fff;
		border-radius: 16rpx;
		padding: 20rpx;
		text-align: center;
		padding-bottom: 40rpx;
		overflow: auto;
	}

	.qiye1 {
		font-size: 32rpx;
		margin-bottom: 10rpx;
	}

	.qiye2 {
		text-align: left;
	}
</style>